home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / CPUCHECK.ASM < prev    next >
Assembly Source File  |  1993-04-05  |  3KB  |  79 lines

  1.         page    55, 132
  2.  
  3. ;  FUNCTION:  cpu_check
  4. ;
  5. ;  Attempt to discover the type of CPU. Use MASM 5.1 or greater.
  6. ;  Returns 86 for 8088/8086, 286 for 80286, 386 for 80386/80486.
  7. ;
  8. ;  Requires MASM 5.1 or later or equivalent
  9. ;
  10. ;  Assemble with:       MASM /Mx /z ...
  11. ;                       TASM /jMASM /mx /z ...
  12. ;
  13.  
  14. %       .MODEL  memodel,C               ;Add model support via
  15.                                         ;command line macros, e.g.
  16.                                         ;MASM /Dmemodel=LARGE
  17.  
  18.         .CODE
  19. ;
  20. ; int cpu_check(void) - returns 86, 186, 286, 386
  21. ;
  22.  
  23.         PUBLIC  cpu_check
  24.  
  25. cpu_check       PROC    USES BX
  26.         pushf
  27.         xor     ax,ax                   ; zero ax
  28.         push    ax
  29.         popf                            ; try to put 0 into flags
  30.         pushf
  31.         pop     ax                      ; see what went in flags
  32.         and     ax,0f000h               ; mask off high flag bits
  33.         cmp     ax,0f000h               ; was high nibble ones
  34.         je      _86                     ; is 8086 or 8088
  35.         push    sp                      ; see if sp is updated
  36.         pop     bx                      ; before or after it is
  37.         cmp     bx,sp                   ; pushed
  38.         jne     _186
  39.         mov     ax,0f000h               ; try to set high bits
  40.         push    ax
  41.         popf                            ; in the flags
  42.         pushf
  43.         pop     ax                      ; look at actual flags
  44.         and     ax,0f000h               ; any high bits set?
  45.         je      _286                    ; is 80286
  46. _386:
  47.         .386                            ; enable 386 instructions
  48.  
  49.         pushfd                          ; save extended flags
  50.         mov     eax,040000h
  51.         push    eax                     ; push 40000h onto stack
  52.         popfd                           ; pop extended flags
  53.         pushfd                          ; push extended flags
  54.         pop     eax                     ; put in eax
  55.         and     eax,040000h             ; is bit 18 set?
  56.         jne     _486                    ; yes, it's a 486
  57.         mov     ax,386                  ; no, it's a 386
  58.         jmp     _386x
  59. _486:
  60.         mov     ax,486
  61. _386x:
  62.         popfd                           ; clean the stack
  63.         jmp     ccexit
  64. _286:
  65.         mov     ax,286                  ; is an 80286
  66.         jmp     ccexit
  67. _186:
  68.         mov     ax,186                  ; is an 80188/80186
  69.         jmp     ccexit
  70. _86:
  71.         mov     ax,86                   ; is an 8088/8086
  72. ccexit:
  73.         popf                            ; restore original flags
  74.         ret                             ; return
  75.  
  76. cpu_check       ENDP    
  77.  
  78.         end
  79.